package com.app.mymusic.adapter;

import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by Administrator on 2016-12-12.
 */

public class MyViewHolder extends RecyclerView.ViewHolder {

    private SparseArray<View> mViews;


    public MyViewHolder(View itemView) {
        super(itemView);
        mViews=new SparseArray<>();
    }

    public  <T extends View>T getView(int  id){
       View mView= mViews.get(id);
        if(mView==null){
            mView=itemView.findViewById(id);
            mViews.put(id,mView);
        }
        return (T) mView;
    }

    public MyViewHolder setText(int id,String str){
        TextView text=getView(id);
        text.setText(str);
        return this;
    }

    public MyViewHolder setImageResource(int viewId,int resId){
        ImageView view= getView(viewId);
        view.setImageResource(resId);
        return this;
    }
    public MyViewHolder setImageBitamp(int viewId,Bitmap bitmap){
        ImageView view= getView(viewId);
        view.setImageBitmap(bitmap);
        return this;
    }
    public MyViewHolder setImageURI(int viewId,String uri){
        ImageView view= getView(viewId);
//        Imageloader.getInstance().loadImg(view,uri);
        return this;
    }
}
